package dao.impl;

import dao.UserDao;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import pojo.User;
import utils.DataSourceUtils;

import java.sql.SQLException;
import java.util.List;

public class UserDaoImpl implements UserDao {

    private QueryRunner qr = new QueryRunner(DataSourceUtils.getDs());

    @Override
    public List<User> findAll() {

        //利用dbutils实现数据库查询操作
        try {
            List<User> userList = qr.query("select * from user", new BeanListHandler<>(User.class));
            return userList;
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return null;
    }
}
